/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.supplier;

import static com.opensymphony.xwork2.Action.INPUT;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import database.ProductManagerDAO;
import database.SupplierDAO;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.Product;
import model.Supplier;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Supplier")
public class WSupplierAction extends ActionSupport{
    private List<Supplier> suppliers;
    private Supplier aSupplier;
    private SupplierDAO supplierDAO = new SupplierDAO();

    /**
     * @return the suppliers
     */
    private Map<Integer, String> allProducts;
    public ProductManagerDAO productDAO = new ProductManagerDAO();
    
     public WSupplierAction() {
        allProducts = new HashMap<Integer, String>();

        
        for (Product c:productDAO.GetAllProduct()) {
            allProducts.put(c.getIdProduct(), c.getName());
        }
    }
    public List<Supplier> getSuppliers() {
        return suppliers;
    }

    /**
     * @param suppliers the suppliers to set
     */
    public void setSuppliers(List<Supplier> suppliers) {
        this.suppliers = suppliers;
    }
    @Action(value= "supplier-management", results = {
	@Result(name ="success",location="/manageSupplier/w_supplier.jsp")
    })
    public String view()
    {    
        //List<Supplier> temp;
        suppliers = supplierDAO.getAllSuppliers();   
        System.out.println(suppliers);
        return SUCCESS;
    }
    @Action(value="add-supplier",
             results = {
                 @Result(name="success", location="/manageSupplier/w_addsupplier.jsp")
             })
     public String AddSupplier()
     {
         return SUCCESS;
     }
//    @Action(value = "addstaff", results = {
//        @Result(name = "success", location = "/w_supplier.jsp"),
//        @Result(name = "input", location = "/w_addsupplier.jsp")
//    })
//    public String execute() throws Exception {
//        String result;
//
////        Memberaccount memberaccount = new Memberaccount(username, password);
////        customer.setMemeberaccount(memberaccount);
////        aStaff.setLoginName(loginName);
////        aStaff.setPassword(password);
//        System.out.println(aSupplier);
//        if (supplierDAO.InsertSupplier(aSupplier)) {
//            addActionMessage("Add staff Successfully!");
//            suppliers = supplierDAO.getAllSuppliers();
//            result = SUCCESS;
//        } else {
//            addActionError("Register Failed (due to existed username or email).");
//            result = INPUT;
//        }
//
//        return result;
//    }

    /**
     * @return the aSupplier
     */
    public Supplier getaSupplier() {
        return aSupplier;
    }

    /**
     * @param aSupplier the aSupplier to set
     */
    public void setaSupplier(Supplier aSupplier) {
        this.aSupplier = aSupplier;
    }

    /**
     * @return the allProducts
     */
    public Map<Integer, String> getAllProducts() {
        return allProducts;
    }

    /**
     * @param allProducts the allProducts to set
     */
    public void setAllProducts(Map<Integer, String> allProducts) {
        this.allProducts = allProducts;
    }
}
